# -*- coding: utf-8 -*-
import KBEngine
from KBEDebug import *
import Functor

class Account(KBEngine.Proxy):
    def __init__(self):
        KBEngine.Proxy.__init__(self)
        if self.IsNewChar == 1:
            self.CreateChar()

    def onClientEnabled( self ):
        pass

    def onLogOnAttempt(self, ip, port, password):
        return KBEngine.LOG_ON_ACCEPT

    def onClientDeath(self):
        if self.cell != None:
            self.destroyCellEntity()
        else:
            self.destroy(False, True)

    def onLoseCell(self):
        self.destroy(False, True)

    def CreateChar(self):
        #创建新角色
        self.IsNewChar = 0
        self.CharId_base = self.databaseID + 100000
        self.CharName_base = "游客" + str(self.CharId_base)
        self.cellData["CharId"] = self.CharId_base
        self.cellData["CharName"] = self.CharName_base
        self.writeToDB()